<?php

include_once 'Vertex.php';
include_once 'Edge.php';

/**
 * Description of Graph
 *
 * @author Dmitry Gorkovets
 */
class Graph {

    private $title = 'Graph title';
    private $xmldata;
    private $width;
    private $height;
    private $edges = array();
    private $vertices = array();

    public function __construct($xmldata) {
        $this->init($xmldata);
    }

    public function init($xmldata) {
        $this->xmldata = $xmldata;
        $xmld = new SimpleXMLElement($xmldata);
        $this->width = strval($xmld->size->attributes()->width);
        $this->height = strval($xmld->size[0]->attributes()->height);

        foreach($xmld->vertices->children() as $v)
        {
            $this->vertices[] = new Vertex(strval($v->attributes()->x), strval($v->attributes()->y));
        }

        foreach($xmld->edges->children() as $e)
        {
            $edge = new Edge();
            $edge->label->text = strval($e->label->attributes()->text);
            $edge->label->x = strval($e->label->attributes()->x);
            $edge->label->y = strval($e->label->attributes()->y);
            foreach($e->points->children() as $p)
            {
                $edge->keypoints[] = new Vertex(strval($p->attributes()->x),
                                               strval($p->attributes()->y));
            }
            $this->edges[] = $edge;
        }
        
    }

    public function getVertices()
    {
        return $this->vertices;
    }
    
    public function getEdges()
    {
        return $this->edges;
    }

    public function getTitle() {
        return $this->title;
    }

    public function getWidth() {
        return $this->width;
    }

    public function getHeight() {
        return $this->height;
    }

}
?>
